package com.qf2.controller;

import com.qf2.domain.Account;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

//@Controller
//@RequestMapping("/account")
public class AccountController {

    //新增账户 http://localhost:80/account
    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public String add(@RequestBody Account account){
        System.out.println("新增账户:" + account);
        return "新增成功";
    }

    //修改账户 http://localhost:80/account
    @RequestMapping(method = RequestMethod.PUT)
    @ResponseBody
    public String update(@RequestBody Account account){
        System.out.println("修改账户:" + account);
        return "修改成功";
    }

    //查询所有账户  http://localhost:80/account
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public List<Account> findAll(){
        List<Account> accounts = new ArrayList<>();
        accounts.add(new Account(1,"zs",1000d));
        accounts.add(new Account(2,"ls",2000d));
        accounts.add(new Account(3,"ww",3000d));

        return accounts;
    }

    //删除账户  http://localhost:80/account/1
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public String del(@PathVariable("id") Integer id){
        System.out.println("删除账户:" + id);
        return "删除成功";
    }

    //查询指定id的账户  http://localhost:80/account/1
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Account findById(@PathVariable("id") Integer id){
        return new Account(1,"zs",1000d);
    }
}
